package com.bullbuddy.dao;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.bullbuddy.po.StaffInfo;

public class StaffInfoDAO extends AbstractDAO<StaffInfo> {

	public List<StaffInfo> find(String staffId,String staffName,String departmentId){
		List<StaffInfo> staInfoList=new ArrayList<StaffInfo>();
		try{
			this.openConnection();
			CallableStatement proc=this.conn.prepareCall("{call staffInfo_query(?,?,?)}");
			proc.setString("staffId", staffId);
			proc.setString("staffName",staffName);
			proc.setString("departmentId", departmentId);
			ResultSet rs=proc.executeQuery();
			StaffInfo staInfo;
			while(rs.next()){
				staInfo=new StaffInfo();
				staInfo.setStaffId(rs.getString("staffId"));
				staInfo.setStaffName(rs.getString("staffName"));
				staInfo.setDeptId(rs.getString("departmentId"));
				staInfo.setReserve(rs.getBytes("reserve"));
				staInfoList.add(staInfo);
			}return staInfoList;
		}catch(SQLException e){
			e.printStackTrace();
		}finally{
			try{
				this.closeConnection();
			}catch(SQLException e){
				e.printStackTrace();
			}
		}
		return null;
	}
	
	@Override
	public List<StaffInfo> findAll() {
		// TODO Auto-generated method stub
		return find(null,null,null);
	}
	public List<StaffInfo> findById(String staffId){
		return find(staffId,null,null);
	}
	

	
}
